Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add support for converting KeyPairs into JWKs #33

Merged
merged 1 commit into from
Jun 10, 2024

Conversation

joonas
Copy link
Member

@joonas joonas commented Jun 7, 2024

Feature or Problem

While implementing a Secrets backend for wasmCloud/wasmCloud#2190, we landed on JWTs as the authentication mechanism, and since we have nkeys readily available, it would be nice to use them for signing the JWTs.

However, to make it easier on the platform operators, we are not going to require them to provide a static list of the possible public keys used for signing, but instead provide a JWKS endpoint that'll host a list of the public nkeys used to sign the JWT.

It turns out it's pretty straight forward to convert an nkey into a JWK, which is why I thought it would be nice to add as a feature to this crate for other folks to use as well.

cc @protochron

Related Issues

Release Information

Consumer Impact

Testing

Unit Test(s)

Acceptance or Integration

Manual Verification

I validated locally using jose-util from the go-jose project that the keys generated with the new JsonWebkey struct, based on a pre-existing nkey, can be used to sign (with seed) and verify (with public key) payloads correctly:

# Using jose-util built from the main branch (i.e. v4)
$ echo "test message v4" > msg-v4.txt
$ jose-util sign -alg EdDSA -key private.jwk.json -in msg.txt -out signed-msg-v4.txt
$ jose-util verify -key public.jwk.json -in signed-msg-v4.txt
test message v4

# Using jose-util built from the v3.0.3 branch
$ echo "test message v3" > msg-v3.txt
$ jose-util sign --alg=EdDSA --key=private.jwk.json --in=msg-v3.txt > signed-msg-v3.txt
$ jose-util verify --key=public.jwk.json --in=signed-msg-v3.txt
test message v3

src/jwk.rs Outdated Show resolved Hide resolved
Copy link
Member

@brooksmtownsend brooksmtownsend left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple requests for a comment addition and typo fix but largely looks great! Nice tests

src/error.rs Outdated Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
src/jwk.rs Outdated Show resolved Hide resolved
@joonas joonas force-pushed the feat/add-jwk-support branch from 8063aaf to 92af7eb Compare June 7, 2024 15:12
@joonas
Copy link
Member Author

joonas commented Jun 7, 2024

@protochron @brooksmtownsend thanks for the feedback, I believe I addressed the outstanding issues 😃

@brooksmtownsend brooksmtownsend merged commit bc92bd3 into wasmCloud:main Jun 10, 2024
3 checks passed
@joonas joonas deleted the feat/add-jwk-support branch June 12, 2024 21:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants